<?php

namespace Trawind\Skeleton\Generators;

use Illuminate\Support\Str;
use Prettus\Repository\Generators\Migrations\SchemaParser;

/**
 * Class ModelGenerator
 * @package Prettus\Repository\Generators
 * @author Anderson Andrade <contato@andersonandra.de>
 */
class ModelGenerator extends Generator
{

    /**
     * Get stub name.
     *
     * @var string
     */
    protected $stub = 'model';

    /**
     * Get root namespace.
     *
     * @return string
     */
    public function getRootNamespace()
    {
        return parent::getRootNamespace() . parent::getConfigGeneratorClassPath($this->getPathConfigNode());
    }

    /**
     * Get generator path config node.
     *
     * @return string
     */
    public function getPathConfigNode()
    {
        return 'models';
    }

    /**
     * Get destination path for generated file.
     *
     * @return string
     */
    public function getPath()
    {
        return $this->getBasePath() . '/' . parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true) . '/' . $this->getName() . '.php';
    }

    /**
     * Get base path of destination file.
     *
     * @return string
     */

    public function getBasePath()
    {
        return config('repository.generator.basePath', app()->path());
    }

    /**
     * Get array replacements.
     *
     * @return array
     */
    public function getReplacements()
    {
        return array_merge(parent::getReplacements(), [
            'table_name' => $this->getTableName(),
            'business_type'=>$this->getBusinessType()
        ]);
    }
    
    
    public function getTableName()
    {
        $tableName= str_replace('/','_',strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', $this->getName())));
        return Str::plural($tableName);
    }

    protected function getBusinessType()
    {
        return strtoupper(config('app.name').'_'.str_replace('/','_',strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', $this->getName()))));
    }
}
